#ifndef CROWBAR_QUEUE_H_INCLUDED
#define CROWBAR_QUEUE_H_INCLUDED


template<typename TYPE, unsigned int CAPACITY> class Queue
{
private:
	TYPE elements[CAPACITY];
	int m_rindex;
	int m_windex;
	int m_count;

public:
	Queue()
	{
		Clear();
	}
	
	bool IsEmpty() const
	{
		return m_count == 0;
	}
	
	bool IsFull() const
	{
		return m_count == CAPACITY;
	}
	
	void Clear()
	{
		m_count = 0;
		m_rindex = 0;
		m_windex = 0;
	}
	
	bool Push(TYPE& elem)
	{
		if (m_count >= CAPACITY) {
			LogError("queue is full");
			return false;
		}
		elements[m_windex] = elem;
		m_count++;
		m_windex = (m_windex + 1) % CAPACITY;
		return true;
	}

	bool PushValue(TYPE elem)
	{
		if (m_count >= CAPACITY) {
			LogError("queue is full");
			return false;
		}
		elements[m_windex] = elem;
		m_count++;
		m_windex = (m_windex + 1) % CAPACITY;
		return true;
	}

	bool Pop(TYPE& elem)
	{
		if (m_count <= 0) {
			LogError("queue is empty");
			return false;
		}
		elem = elements[m_rindex];
		m_count--;
		m_rindex = (m_rindex + 1) % CAPACITY;
		return true;
	}
};



#endif // CROWBAR_QUEUE_H_INCLUDED